package net.lcheng.service.impl;

import net.lcheng.dao.BaseAreasMapper;
import net.lcheng.model.BaseAreas;
import net.lcheng.model.BaseAreasExample;
import net.lcheng.service.BaseAreasService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zwr on 2016/7/1 0001.
 */
@Service
public class BaseAreasServiceImpl implements BaseAreasService {
   @Resource
   private BaseAreasMapper mapper;
    @Override
    public List<BaseAreas> getParentCodeByAreaName(String parentCode) {
        BaseAreasExample example=new BaseAreasExample();
        if(com.alibaba.druid.util.StringUtils.isEmpty(parentCode)){
            example.or().andParentCodeIsNull();
            example.or().andParentCodeEqualTo("");
        }else example.or().andParentCodeEqualTo(parentCode);
        return mapper.selectByExample(example);
    }

    @Override
    public List<BaseAreas> getAreaCodeListByAreaName(String areaCode) {
        BaseAreasExample example=new BaseAreasExample();
        if(com.alibaba.druid.util.StringUtils.isEmpty(areaCode)){
            example.or().andAreaCodeIsNull();
            example.or().andAreaCodeEqualTo("");
        }else example.or().andAreaCodeEqualTo(areaCode);
        return mapper.selectByExample(example);
    }

    @Override
    public BaseAreas getAreaCodeByAreaName(String areaCode) {
        BaseAreasExample example=new BaseAreasExample();
        example.or().andAreaCodeEqualTo(areaCode);
        List<BaseAreas> list=mapper.selectByExample(example);
        if (list!=null&& list.size()>0){
            return list.get(0);
        }else
        return null;
    }
}
